<page-grid>
    <sf
        #sf
        mode="search"
        [schema]="searchSchema"
        autocomplete="off"
        [formData]="params"
        (formSubmit)="searchDataGet($event)"
        (formReset)="reSetDataGet(params)"
    />
    <div space-card>
        <button nz-button *aclIf="['admin', 'system:menu:add']" [nzType]="'primary'" (click)="addDept()">
            <i nz-icon nzType="plus" nzTheme="outline"></i>新增
        </button>
        <button nz-button [nzType]="'default'" (click)="expandTableAll()">
            <i nz-icon nzType="swap" style="transform: rotate(90deg)" nzTheme="outline"></i>展开/折叠
        </button>
    </div>
    <div>
        <nz-table #expandTable nzSize="small" [nzData]="listOfMapData" [nzFrontPagination]="false" nzTableLayout="fixed">
            <thead>
                <tr>
                    <th style="width: 260px">部门名称</th>
                    <th style="width: 200px; text-align: center">排序</th>
                    <th style="width: 80px">状态</th>
                    <th style="width: 160px; text-align: center">创建时间</th>
                    <th style="text-align: center">操作</th>
                </tr>
            </thead>
            <tbody>
                <ng-container *ngFor="let data of expandTable.data">
                    <ng-container *ngFor="let item of mapOfExpandedData[data.key]">
                        <tr *ngIf="(item.parent && item.parent.expand) || !item.parent">
                            <td
                                [nzIndentSize]="item.level! * 20"
                                [nzShowExpand]="!!item.children && item.children.length > 0"
                                [(nzExpand)]="item.expand"
                                (nzExpandChange)="collapse(mapOfExpandedData[data.key], item, $event)"
                            >
                                {{ item.deptName }}
                            </td>
                            <td style="width: 200px; text-align: center">{{ item.orderNum }}</td>
                            <td><dict-tag [value]="item.status" dictKey="sys_normal_disable" /></td>
                            <td>{{ item.createTime }}</td>
                            <td style="text-align: center">
                                <a nz-button nzType="link" *aclIf="['admin', 'system:dept:edit']" (click)="editDept(item)">
                                    <i nz-icon nzType="edit" nzTheme="outline"></i>修改
                                </a>
                                <nz-divider nzType="vertical" />
                                <a nz-button nzType="link" *aclIf="['admin', 'system:dept:add']" (click)="addSubDept(item)">
                                    <i nz-icon nzType="plus" nzTheme="outline"></i>新增
                                </a>
                                <ng-container *ngIf="item.parentId !== 0">
                                    <nz-divider nzType="vertical" />
                                    <a nz-button nzType="link" nzDanger *aclIf="['admin', 'system:dept:remove']" (click)="delDept(item)">
                                        <i nz-icon nzType="delete" nzTheme="outline"></i>删除
                                    </a>
                                </ng-container>
                            </td>
                        </tr>
                    </ng-container>
                </ng-container>
            </tbody>
        </nz-table>
    </div>
</page-grid>
